<template>
  <dv-border-box-8 style="padding-top: 10px ">
    <dv-decoration-7 style="width:100%;height:30px;">销售统计</dv-decoration-7>
    <div id="SaleStatistics" style="width: 100%;height: 250px"></div>
  </dv-border-box-8>
</template>

<script>
import {getSaleStat} from "@/api/dv/carbon";

export default {
  name: "SaleStatistics",
  data() {
    return  {
      saleData: [],
    }
  },
  mounted(){
    this.initEchart();
  },
  methods:{
    getData() {
      return new Promise((resolve, reject) => {
        getSaleStat().then(response => {
          resolve(response.data)
        });
      })
    },
    initEchart(){
      let data = this.getData()
      data.then( res => {
        let date = res.dateList
        let sold = res.numList
        let contractAmount = res.numList2

        let myChart = this.$echarts.init(document.getElementById('SaleStatistics'),'dark');

        let option = {
          backgroundColor: '',
          tooltip: {
            trigger: 'axis'
          },
          legend: {
            data: ['总销售额','合同额']
          },
          grid: {
            left: '3%',
            right: '4%',
            bottom: '3%',
            containLabel: true
          },
          xAxis: {
            type: 'category',
            boundaryGap: false,
            data: date
          },
          yAxis: {
            type: 'value',
            name: '销售额'
          },
          series: [
            {
              name: '总销售额',
              type: 'line',
              smooth: true,
              tooltip: {
                valueFormatter: function (value) {
                  return value + ' 万';
                }
              },
              data: sold
            },
            {
              name: '合同额',
              type: 'line',
              smooth: true,
              tooltip: {
                valueFormatter: function (value) {
                  return value + ' 万';
                }
              },
              data: contractAmount
            }
          ]
        };

        option && myChart.setOption(option);
      })


    }
  }
}
</script>

<style scoped>

</style>
